//
//  WQAccount.swift
//  sanwuWeibo
//
//  Created by 王先强 on 15/12/9.
//  Copyright © 2015年 王先强. All rights reserved.
//

import UIKit

class WQAccount: NSObject, NSCoding {
    //用户信息
    var access_token: String?
    var expires_in: NSTimeInterval = 0 {
        didSet{
            
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    var uid: String?
    var screen_name: String?
    var avatar_large: String?
    var expiresDate: NSDate?
    
    init(dict:[String: AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    func encodeWithCoder(coder: NSCoder) {
        coder.encodeObject(access_token, forKey: "access_token")
        coder.encodeObject(expiresDate, forKey: "expiresDate")
        coder.encodeObject(uid, forKey: "uid")
        coder.encodeObject(screen_name, forKey: "screen_name")
        coder.encodeObject(avatar_large, forKey: "avatar_large")
        
    }
    
     required init?(coder encoder: NSCoder) {
        access_token = encoder.decodeObjectForKey("access_token") as? String
        expiresDate = encoder.decodeObjectForKey("expiresDate") as? NSDate
        uid = encoder.decodeObjectForKey("uid") as? String
        screen_name = encoder.decodeObjectForKey("screen_name") as? String
        avatar_large = encoder.decodeObjectForKey("avatar_large") as? String
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
//    override var description: String {
//        let keys = ["access_token", "expires_in", "uid"]
//        
//        return dictionaryWithValuesForKeys(keys).description
//    }
    override var description: String {
        return descriptionFromClazz(self.classForCoder)
    }
}
